<?php

class Activity_WidgetController extends Zend_Controller_Action
{
	public function latestsAction()
	{
		$entClass = $this->_getParam('entity_class');
		$entId = intval($this->_getParam('entity_id'));

		if (empty($entClass) === FALSE || intval($entId) > 0) {
			$entObj = Euso_Object::getInstance($entClass, $entId);
		}

		if (isset($entObj)) {
			$instances = Activity_Model_Activity::getNewestsByObject($entClass, $entId, 50);
		} else {
			$instances = Activity_Model_Activity::getNewests(50);
		}

		//TODO: build the sentences here
		foreach ($instances as $inst) {
			$act = array();
			$subject = $inst->getSubject();
			$entObject = $subject->getObjectInstance();
			if (empty($entClass) === FALSE && $entId > 0) {
				if ($entClass == $subject->getObjectClassIdName() && $entId == $subject->getObjectId()) {
					$act['transitivity'] = 'transitive';
				} else {
					$act['transitivity'] = 'intransitive';
				}
			} else {
				$act['transitivity'] = 'transitive';
			}
			$act['subjectNicename'] = $entObject->getNicename();
			$act['subjectUrl'] = site_url_base('/'. $subject->getObjectClassIdName() .'/'. $entObject->getIdName());
			$inst->setParams($act);
		}

		$this->view->activityList = $instances;
	}
}